package com.androidy;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

public class custAnimationListener implements AnimationListener{
	Animation animate = null;
	Intent i = null;
	Context c = null;
	Boolean visible = false;
	View target = null;
	
	public custAnimationListener (String type, View mtarget, int duration, int offset, float from, float to){
		if (type == "alpha"){
			animate = new AlphaAnimation(from, to);
		} else if (type == "rotate"){
			animate = new RotateAnimation(from, to);	
		}
		if (animate != null){
			animate.setDuration(duration);
			animate.setStartOffset(offset);
			animate.setAnimationListener(this);				
		}
	}
	public custAnimationListener (String type, int duration, int offset, float fromx, float fromy, float tox, float toy){
		if (type == "rotate"){
			animate = new RotateAnimation(fromx, fromy, tox, toy);
		} else if (type == "scale"){
			animate = new ScaleAnimation(fromx, tox, fromy, toy);
		} else if (type == "transform"){
			animate = new TranslateAnimation(fromx, tox, fromy, toy);
		}
		if (animate != null){
			animate.setDuration(duration);
			animate.setStartOffset(offset);
			animate.setAnimationListener(this);				
		}
	}	
	
	public void startAnimation(View mtarget, boolean mvisible){
		i = null;
		c = null;
		visible = mvisible;
		target = mtarget;
		target.startAnimation(animate);
	}
	
	public void startAnimation(View mtarget, boolean mvisible, Intent mi, Context mc){
		i = mi;
		c = mc;
		visible = mvisible;
		target = mtarget;
		target.startAnimation(animate);
	}
	
	@Override
	public void onAnimationStart(Animation animation) {
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		if (visible == true)
			target.setVisibility(View.VISIBLE);
		else 
			target.setVisibility(View.INVISIBLE);
		if ((i != null) && (c != null)){
			c.startActivity(i);		
		}
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
			
	}

}
